package 练习02_多线程穷举法破解密码;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * @ClassName: TestThreadGuesspwd
 * @Author: AllenSun
 * @Date: 2022/3/18 下午9:43
 */
public class TestThreadGuesspwd {
    public static boolean found = false;

    public static void main(String[] args) {
        String pwd = randomPwd(4);
        System.out.println("生成的密码是："+pwd);
        SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        System.out.println("当前时间是："+df.format(new Date()));
        List<String> pwdList = new ArrayList<>();
        PassWordThread passWordThread = new PassWordThread(pwd,pwdList);
        new Thread(passWordThread).start();
        // new LogThread(pwdList).start();

    }

    public static String randomPwd(int length) {
        String pool = "";
        for (short i = '0'; i <= '9'; i++) {
            pool += (char) i;
        }
        for (short i = 'a'; i <= 'z'; i++) {
            pool += (char) i;
        }
        for (short i = 'A'; i <= 'Z'; i++) {
            pool += (char) i;
        }
        char cs[] = new char[length];
        for (int i = 0; i < cs.length; i++) {
            int index = (int) (Math.random() * pool.length());
            cs[i] = pool.charAt(index);
        }
        String result = new String(cs);
        return result;
    }
}
